import React from 'react'
import { useNavigate } from 'react-router-dom'
import http from '../../api/http'
import { Button, Form,Input } from 'antd-mobile'

const Login = () => {
     const nav=useNavigate()
     const onFinish = async(values) => {
        // console.log(values,11);
     const res=await http.post("/api/login",values)
    //  console.log(res,22);
     const {data,code,message}=res.data
     if(code===40004){
        // localStorage.setItem("token",data.token)
        alert("登录成功")
        nav("/")
     }else{
        alert("登录失败")
     }
  }
  return (
    <div>
      登录
      <Form
        onFinish={onFinish}
        layout='horizontal'
        footer={
          <Button block type='submit' color='warning' size='large'>
            登录
          </Button>
        }
      >
        <Form.Item
          name='username'
          label='账号'
          rules={[{ required: true, message: '账号不能为空' }]}
        >
          <Input placeholder='请输入账号' />
        </Form.Item>
        <Form.Item
          name='password'
          label='密码'
          rules={[{ required: true, message: '密码不能为空' }]}
        >
          <Input placeholder='请输入密码' />
        </Form.Item>

      </Form>
    </div>
  )
}

export default Login
